package com.twopai.framelibrary.mvp;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.lang.ref.WeakReference;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Author:twopai
 * Date:2018/6/26
 * Description:
 */
public abstract class BaseActivity extends AppCompatActivity {

    private WeakReference<BaseActivity> weakReference;
    private Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int layoutId = this.getLayoutId();
        if (layoutId != 0) {
            setContentView(layoutId);
        }
        unbinder = ButterKnife.bind(this);
        iniTitle();
        initView(savedInstanceState);
        initData();
        weakReference = new WeakReference<>(this);
        ActivityStackManager.getInstance().addActivity(weakReference);
    }

//    @Override
//    protected void onResume() {
//        super.onResume();
//        MobclickAgent.onResume(this);       //统计时长
//    }
//
//    @Override
//    protected void onPause() {
//        super.onPause();
//        MobclickAgent.onPause(this);
//    }

    /**
     * back
     *
     * @param view
     */
    public void back(View view) {
        finish();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        if (weakReference != null) {
            ActivityStackManager.getInstance().removeActivity(weakReference);
        }
    }
    /**
     * 设置布局
     *
     * @return
     */
    public abstract int getLayoutId();

    /**
     * 初始化视图
     */
    public abstract void iniTitle();

    public abstract void initView(@Nullable Bundle savedInstanceState);

    public abstract void initData();


}
